Skip to content

fix: reloaded fit curve matches the original#28

Open
ahmadomira wants to merge 1 commit into
mainfrom
fix/reloaded-fit-curve
Open

fix: reloaded fit curve matches the original#28
ahmadomira wants to merge 1 commit into
mainfrom
fix/reloaded-fit-curve

Conversation

@ahmadomira

Copy link
Copy Markdown
Collaborator

Summary

A reloaded Median Fit curve did not match the line drawn during the original fit.

Root cause: the smooth fit line is fully determined by the fitted parameters, the assay conditions, the assay type, and the data x-range — but the display layer trusted the resolution serialized in FitResult.x_fit/y_fit. Exports made before the dense-curve change (commit d532d9d), and the linear / failed-fit paths, stored the curve only at the measured concentrations. On reload the line was therefore drawn as coarse straight segments that no longer matched the dense curve a fresh fit renders.

Fix: re-derive the dense curve from the stored parameters + conditions at render time via a new resolve_fit_curve(), instead of trusting the serialized arrays. Serialization stays faithful (to_dict/from_dict unchanged), so the fix lives in the display path:

  • core/pipeline/fit_pipeline.pyresolve_fit_curve() rebuilds a minimal assay from the result's assay_type + conditions and re-evaluates _dense_fit_curve(); falls back to the stored arrays when the curve can't be rebuilt (unknown/linear assay, no parameters, invalid conditions).
  • core/data_processing/plotting.pyprepare_plot_data() uses it (covers the common reload paths).
  • gui/fitting_session.py — the source-file-missing import branch uses it too.

A reloaded fit now renders the identical line regardless of the serialized resolution; fresh fits are unchanged (the regenerated curve is bit-identical to the stored one).

Tests

New tests/unit/test_fit_curve_reload.py:

  • reproduces the mismatch (a sparse/old-format export reloads to a 30-pt line) and asserts it now densifies to the 300-pt original curve within float tolerance;
  • a current (dense) export still renders the identical curve after reload;
  • DYE_ALONE (linear) falls back to the stored arrays.

uv run pytest -k "reload or plot or pipeline" passes (65); full unit layer green (373 passed, 3 skipped); ruff check + format clean.

Closes #25

The smooth Median Fit line is fully determined by the fitted parameters,
the assay conditions, the assay type, and the data x-range, yet the display
trusted the resolution serialized in x_fit/y_fit. Exports made before the
dense-curve change (and the linear/failed-fit paths) stored the curve only
at the measured concentrations, so a reloaded fit was drawn as coarse
straight segments that no longer matched the original.

Re-derive the dense curve from the stored parameters at render time via
resolve_fit_curve(), falling back to the serialized arrays when the curve
cannot be rebuilt. Reload now renders the identical line regardless of the
serialized resolution.

Closes #25
Copilot AI review requested due to automatic review settings June 25, 2026 15:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +102 to +105
stored = (result.x_fit, result.y_fit)
if not result.parameters:
return stored
try:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: reloaded fit curve does not match the originally displayed fit

2 participants